package hu.kisprof.quiz.view;

import hu.kisprof.quiz.view.panels.QuizEditPlayersPanel;
import hu.kisprof.quiz.view.panels.QuizEditQuestionsPanel;
import hu.kisprof.quiz.view.panels.QuizStatisticPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;



public class QuizMenuBar extends JMenuBar implements ActionListener{

	private static final long serialVersionUID = -4756881376235943828L;
	public static final int SIMPLEUSER = 0;
	public static final int ADMINUSER = 1;
	public static final int NOUSER = -1;
	private QuizGUI gui;
	public QuizMenuBar(QuizGUI gui,int i) {
		super();
		this.gui = gui;
		createMenuPoint(Labels.file,Labels.exit);
		/*if(i==SIMPLEUSER||i==ADMINUSER){
			createMenuPoint(Labels.stat,Labels.playerStats);
		}*/
		if(i==ADMINUSER){
			createMenuPoint(Labels.admin,Labels.editQuestions,Labels.editUsers);
			createMenuPoint(Labels.stat,Labels.goodAnsPerCity,Labels.goodAnsPerTopic,Labels.bestPlayerByTopic,
										Labels.usedTopics,Labels.hardestQAnsweredByPlayers,Labels.aboveAvaragePointUsers);
		}
	}
	
    private void createMenuPoint(String name, String... subnames){
        JMenu menu;
        menu = new JMenu(name);
        this.add(menu);
        for(String subname : subnames){
        	JMenuItem menuItem = new JMenuItem(subname);
	        menu.add(menuItem);
	        menuItem.addActionListener(this);
        }
    }
	
	
	

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals(Labels.exit)){
			System.exit(0);
		}
		if(e.getActionCommand().equals(Labels.editQuestions)&&!gui.getControl().isInGame()){
			gui.setActualContent(new QuizEditQuestionsPanel(gui));
		}
		if(e.getActionCommand().equals(Labels.editUsers)&&!gui.getControl().isInGame()){
			gui.setActualContent(new QuizEditPlayersPanel(gui));
		}
		if(e.getActionCommand().equals(Labels.goodAnsPerCity)&&!gui.getControl().isInGame()){		
			gui.setActualContent(new QuizStatisticPanel(gui,gui.getControl().getStatistic(1)));
		}
		if(e.getActionCommand().equals(Labels.goodAnsPerTopic)&&!gui.getControl().isInGame()){		
			gui.setActualContent(new QuizStatisticPanel(gui,gui.getControl().getStatistic(2)));
		}
		if(e.getActionCommand().equals(Labels.bestPlayerByTopic)&&!gui.getControl().isInGame()){		
			gui.setActualContent(new QuizStatisticPanel(gui,gui.getControl().getStatistic(3)));
		}
		if(e.getActionCommand().equals(Labels.usedTopics)&&!gui.getControl().isInGame()){		
			gui.setActualContent(new QuizStatisticPanel(gui,gui.getControl().getStatistic(4)));
		}
		if(e.getActionCommand().equals(Labels.hardestQAnsweredByPlayers)&&!gui.getControl().isInGame()){		
			gui.setActualContent(new QuizStatisticPanel(gui,gui.getControl().getStatistic(5)));
		}
		if(e.getActionCommand().equals(Labels.aboveAvaragePointUsers)&&!gui.getControl().isInGame()){		
			gui.setActualContent(new QuizStatisticPanel(gui,gui.getControl().getStatistic(6)));
		}
		
	}

}
